package com.ieheima.demo;

import java.io.*;
import java.util.ArrayList;

public class ObjectClass02 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student s1 = new Student("张三", 23);
        Student s2 = new Student("李四", 24);
        Student s3 = new Student("王五", 25);

        //用集合装入Student对象，序列化集合
        ArrayList<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);

        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream("day13\\d.txt"));
        oos.writeObject(list);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(
                new FileInputStream("day13\\d.txt"));
        Object o = ois.readObject();
        ArrayList<Student> list1 = (ArrayList<Student>) o;
        for (Student student : list1) {
            System.out.println(student);
        }
        ois.close();
    }
}
